const fs = require('fs')
const path = require('path')

// 统一生成writeStream
function createWriteStream(fileName) {
  const fullFileName = path.join(__dirname, '../../', 'logs', fileName)
  const writeStream = fs.createWriteStream(fullFileName, {
    flags: 'a' //'a'为追加，'w'为覆盖
  })
  return writeStream
}

// 写入日志
// ssh-rsa B3NzaC1yc2EAAAADAQABAAACAQCiqrDZJRJAoN0LkOQ7P5pKf9LkNFkNkx5w2QcI4SUKxWCZz+PXSJAtnEG1mA2FIPZtQFu6AfKureAdgQZquAZq+5tzqyMTeSU5zsamHwXeXt24d5it5ibDpkWxR3Azxl5iPWDW9SXpbGKMysimPqnciu5WjPcs2nHGuovJGPwz2y8bwX97fCo1G7LZ6daHcegPdzozDp045YxO0usvIdTAh2k8V7Ody9HuUMpRNFdhARJjvDl26fAZACUk5CfgyRUM4kcoHMjMiv35hqDfjUJAnQcCkixWJXlqgPS72pPl5Ek7g1chkQZKR46FPeEl0bTB4645/8ADXfSkfy2rY1kWEToVjUQvLedBxHLtgFASTTHOuzqzyM17P19HfmrY3uF69fR7zeXJG3YBi6GAb8gx58//LnNAjJlib/uPerNbws5/LvBKRea00ORQkYR4W2mHuQcp+ArodD6nmcZVjXmN+guL9j0mcfd9p0jKmxDlgEJSfCUqB26JYeC1og9UPjZL7Y3xPaors1UIoY2hZaQ43dG9JYX2jI16bZeHdTKWdegoyI9QJmccRUzdPjhj7+3MVOe4e7cQ/4Ty3zYbXLgCsFGMex56aG9Ej7BZcAQBC2KPticxMoSO5Yuk96z8jtsZ/eAf5njoaVXevPyUfKX1wWiamSIcMpFjm3+1rXfFdw== aixiami1029@163.com
function writeLog(writeStream, log) {
  writeStream.write(log + '\n')
}

// 访问日志的writeStream
const accessWriteStream = createWriteStream('access.log')

function access(log) {
  writeLog(accessWriteStream, log.content)
}

module.exports = {
  access
}